class Solution
{
public:
    const int mod = 1e9 + 7;
    int qmi(long long x, int n, int mod)
    {
        int sum = 1;
        x %= mod;
        while (n > 0)
        {
            if (n & 1)
            {
                sum = sum * x % mod;
            }

            x *= x;
            x %= mod;
            n /= 2;
        }
        return sum % mod;
    }
    int dfs(vector<vector<int>> &g, int x, int father)
    {
        int d = 0;
        for (int y : g[x])
        {
            if (y != father)
                d = max(d, dfs(g, y, x) + 1);
        }
        return d;
    }
    int assignEdgeWeights(vector<vector<int>> &edges)
    {
        int n = edges.size() + 1;
        vector<vector<int>> g(n + 1);
        for (auto &c : edges)
        {
            int l = c[0], r = c[1];
            g[l].push_back(r);
            g[r].push_back(l);
        }
        int k = dfs(g, 1, 0);
        return qmi(2, k - 1, mod);
    }
};